import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# TODO 第一种普通方式
# 打开浏览器访问网址
driver = webdriver.Chrome()
driver.get('https://sahitest.com/demo/selectTest.htm')

# driver.find_element()
# webelement.find_elelment()--以标签的形式定位，即定位的是当前webelement的后代标签
time.sleep(2)
select = driver.find_element(By.ID,'s1')
select.find_element(By.XPATH,'//select[@id="s1"]/option[2]').click()

print(select.find_element(By.TAG_NAME,'option').get_attribute('outerHTML'))
print(select.find_element(By.CSS_SELECTOR,'option').get_attribute('outerHTML'))
print(select.find_element(By.CSS_SELECTOR,'select>option:nth-child(2)').get_attribute('outerHTML'))

# 退出浏览器
time.sleep(2)
driver.quit()